package vip.xiaonuo.smzq.modular.lifecycle.util;

import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;


public class FileUtils {
    /**
     * 得到图片的base64字符串
     * @param imgPath
     * @return
     */
    public static String getBase64ImgStr(String imgPath){
        Path path = new File(imgPath).toPath();
        byte[] imageBytes = null;
        try {
            imageBytes = Files.readAllBytes(path);
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 将字节数组转换为Base64编码的字符串
        String base64ImageString = Base64.getEncoder().encodeToString(imageBytes);
        return base64ImageString;
    }
}
